using System;
using System.Collections;
using System.Windows.Forms;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;
using Northwind;

namespace ORMappingWithEUSS
{
	public class Program
	{	
		[STAThread]
		static void Main()
		{	
			ObjectService os = new ObjectService("engines.config");
			ObjectContext oc = os.CreateObjectContext();

			//Loading all Customers
            IList customers = oc.Load<Customer>(typeof(Customer));

//			//Loading specific Customer from criteria
            //IList customers = pm.Load<Customer>(typeof(Customer), "[City='London' and ContactName='Hari Kumar']");

            //Loading all Customers and theirs assocated orders (optimize database access)
            //Query query = new Query(typeof(Customer));
            //query.InferredRelationships.Add("Orders");
            //IList customers = pm.Load<Customer>(query);

            //Loading top 10 Customers and theirs assocated orders (optimize database access)
            //Query query = new Query(typeof(Customer));
            //query.OrderBy.Add("CompanyName");
            //query.InferredRelationships.Add("Orders");
            //query.MaxResults = 10;
            //IList customers = pm.Load<Customer>(query);

			//Write each loaded Customer (Parent) and its Orders (Children)
			foreach(Customer customer in customers)
			{
				Console.WriteLine(customer.ContactName + " : ");
				foreach(Order order in customer.Orders)
				{
					Console.WriteLine(order.ShipName + ", " + order.OrderDate);
				}
			}

            Console.WriteLine("End of program...");
			Console.ReadLine();
		
		}

	}
}